package org.his.controller.modular.caiwu;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.his.dao.MemberCardlnfoDao;
import org.his.dao.PatmentDao;
import org.his.dao.PatmentInfoDao;
import org.his.pojo.caiwu.Patment;
import org.his.pojo.caiwu.PatmentInfo;
import org.his.pojo.huiyuan.MemberCardInfo;
import org.his.pojo.liucheng.Reserve;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RequestMapping("/patment")
@Controller
public class PatmentController {

    @Autowired
    private PatmentDao patmentDao;

    @Autowired
    private PatmentInfoDao patmentInfoDao;

    @Autowired
    private MemberCardlnfoDao memberCardlnfoDao;

    @RequestMapping("/index")
    public String index()throws Exception{
        return "modular/caiwu/index";
    }


    @RequestMapping("/getlist")
    @ResponseBody
    public Map<String ,Object> getList(@RequestParam(defaultValue = "1")Integer page, @RequestParam(defaultValue = "10") Integer limit, Patment patment) throws Exception{
        Map<String ,Object> map = new HashMap<>();

        Page<Patment> pa = PageHelper.startPage(page,limit);
        List<Patment> patmentList = patmentDao.getList(patment);

        map.put("code",0);
        map.put("msg",null);
        map.put("count",pa.getTotal());
        map.put("data",patmentList);

        return map;
    }

    @RequestMapping("/get")
    @ResponseBody
    public Patment get(String memberCaseNo) throws Exception{
        return patmentDao.getPatmentByCaseNo(memberCaseNo);
    }

    @RequestMapping("/batchDelete")
    @ResponseBody
    public Map<String,Object> batchDelete(Integer ids) throws Exception{
        Map<String,Object> map = new HashMap<>();
        patmentDao.delete(ids);
        return map;
    }


    @RequestMapping("/jiezhang")
    public String jiezhang()throws Exception{
        return "modular/caiwu/jiezhang";
    }
    @RequestMapping("/xiangqing")
    public String xiangqing()throws Exception{
        return "modular/caiwu/chakan";
    }

    @RequestMapping("/getPayId")
    @ResponseBody
    public Object getPayId(Integer caseNo,Integer pstate)throws Exception{
        return patmentDao.getMemberCaseNo(caseNo,pstate);
    }


    @RequestMapping("/getgetPatmentInfo")
    @ResponseBody
    public List<PatmentInfo> getPatmentInfo(Integer payId)throws Exception{
        return patmentInfoDao.getPatmentInfoList(payId);
    }

    @RequestMapping("/getyue")
    @ResponseBody
    public String getyue(Integer menberId) throws Exception{
        return memberCardlnfoDao.getyue(menberId);
    }

    @RequestMapping("/zhifu")
    @ResponseBody
    public Map<String,Object> zhifu(Integer payId ,String moneyType,String remark) throws Exception{
        Map<String,Object> map = new HashMap<>();

        Patment patment= new Patment();
        patment.setPayId(payId);
        patment.setMoneyType(moneyType);
        patment.setRemark(remark);

        patmentDao.zhifu(patment);

        return map;
    }

}
